package com.kfd.demo.service.Impl;

import com.google.gson.Gson;
import com.kfd.demo.dao.CouponDao;
import com.kfd.demo.entity.Reqs;
import com.kfd.demo.service.CouponServe;
import com.kfd.demo.util.JsonConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CouponServeImpl implements CouponServe {

    @Autowired
    CouponDao couponDao;

    @Override
    public List geUsertCoupons(int uid) {
        //获取用户的优惠券
        System.out.println("我在服务" + uid);
        return couponDao.getUserHaveCoupon(uid);
    }

    @Override
    public List getRandom() {
        return null;
    }

    @Override
    public Reqs RedCode(String redcode, int uid) {
        System.out.println("优惠券兑换码" + redcode);
        int metacode;
        switch (redcode) {
            case "vip666":
                System.out.println("获取vip满减优惠券");
                metacode = 200;

                couponDao.addCoupon(uid, 2);
                break;
            case "vip888":
                System.out.println("获取vipkfc券");
                metacode = 200;

                couponDao.addCoupon(uid, 1);
                break;
            default:
                System.out.println("兑换码错误");
                metacode = 400;
                break;
        }
//        Gson gson = new Gson();
        return new Reqs(metacode, "兑换码", couponDao.getUserHaveCoupon(uid));
    }

    @Override
    public int delCoupon(int uid, int coupid) {
        return couponDao.delCoupon(uid, coupid);
    }
}
